package biz.ezcom.spring.aop.service.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserAop {
	/**
	 * advice中：
	 * 		1:@Around(before),@Aefore (annotation与xml方式,执行顺序不同,与注册先后有部分关系) 
	 * 		2:目标方法 
	 * 		3:目标方法有Exception:
	 * 					1)@AfterThrowing
	 * 					2)@After
	 * 		3:目标方法无Exception:
	 * 					1)@AfterRetruning,@Around(after),@After(annotation与xml方式,执行顺序不同,与注册先后有部分关系)
	 * 
	 * advice的执行顺序,annotation与xml方式执行顺序不同(注册的先后有部分关系)
	 * 实际开发中不应考虑同一等级的advice的执行顺序 
	 */
	@Pointcut("execution (public * biz.ezcom.spring.aop.service.impl.UserServiceImpl.save*(..))")
	public void pointcut() {
	};// Pointcut的方法名不能叫execution

	@Around(value = "pointcut()")
	public void around(ProceedingJoinPoint proceedingJoinPoint)
			throws Throwable {
		System.out.println("UserAop.around():before");
		proceedingJoinPoint.proceed();// 目标方法
		System.out.println("UserAop.around():after");
	}

	@Before(value = "pointcut()")
	public void before() {
		System.out.println("UserAop.before()");
	}

	@After(value = "pointcut()")
	public void after() {
		System.out.println("UserAop.after()");
	}

	@AfterThrowing(value = "pointcut()")
	public void afterThrowing() {
		System.out.println("UserAop.afterThrowing()");
	}

	@AfterReturning(value = "pointcut()")
	public void afterReturning() {
		System.out.println("UserAop.afterReturning()");
	}

}
